package com.itheima.day6;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Demo3 {
    public static void main(String[] args) {


    //创建一个集合
    HashMap<Student,String> hs = new HashMap<>();
    //创建键的对象
    Student s1 = new Student("张三",17);
    Student s2 = new Student("王五",17);
    Student s3 = new Student("赵四",17);
    //添加键与值  值为祖
    hs.put(s1,"北京");
    hs.put(s2,"南京");
    hs.put(s3,"东京");
        Set<Student> s = hs.keySet();
        for (Student stu : s) {
            String s4 = hs.get(stu);
            System.out.println(stu+s4);
        }
/*    hs.forEach((Student st,String s)->{
        System.out.println(st+s);
    });*/
    //通过方法获得键
       /* Set<Map.Entry<Student, String>> entries = hs.entrySet();
        //遍历集合
        for (Map.Entry<Student, String> en : entries) {
            Student key = en.getKey();
            String value = en.getValue();
            System.out.println(key+value);
        }*/
    }

}